//
//  KLDateTool.m
//  KLCurrency
//
//  Created by apple on 2018/1/8.
//  Copyright © 2018年 bonc. All rights reserved.
//

#import "KLDateTool.h"

static const NSInteger secondsPerDay = 24 * 60 * 60;

@implementation KLDateTool

/**
 * 连续日期数据，用于测试使用，由于免费账户不支持连续日期查询
 */
+ (NSArray<NSString *> *)recentWeekPeriodDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<7; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentMonthPeriodDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<30; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentSixMonthsPeriodDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<183; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentYearPeriodDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<366; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentThreeYearsPeriodDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<1096; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}


/**
 * 间隔日期数据，用于实际网络请求使用，由于免费账户不支持连续日期查询，自行拼接相同间隔的6个日期的数据作为最终结果
 * 为了方便操作暂时统一设为6个
 */
+ (NSArray<NSString *> *)recentWeekPeriodGapDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<6; i++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentMonthPeriodGapDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<30; i+=5) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentSixMonthsPeriodGapDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<180; i+=30) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentYearPeriodGapDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<360; i+=60) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

+ (NSArray<NSString *> *)recentThreeYearsPeriodGapDates {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSMutableArray *temp = [NSMutableArray array];
    for (int i = 0; i<1080; i+=180) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*secondsPerDay];
        NSString *dateStr =[formatter stringFromDate:date];
        [temp addObject:dateStr];
    }
    NSArray *array = [[temp reverseObjectEnumerator] allObjects];
    return array;
}

@end
